using System.Collections.Generic;
using System.Linq;
using Microsoft.Practices.Unity;
using TFS.Kanban.Commons.Container;

namespace TFS.Kanban.Commons.Extensions
{
    public static class UnityContainerExtensions
    {
        public static IUnityContainer RegisterView<TView, TViewModel>(this IUnityContainer container, params InjectionMember[] injectionMembers)
        {
            var members = new HashSet<InjectionMember>(injectionMembers)
                              {
                                  new InjectionProperty("DataContext", container.Resolve<TViewModel>())
                              };

            return container.RegisterType<TView>(new ContainerControlledLifetimeManager(), members.ToArray());
        }

        public static IUnityContainer Install(this IUnityContainer container, params IUnityContainerInstaller[] installers)
        {
            foreach (var installer in installers)
            {
                installer.Install(container);
            }

            return container;
        }
    }
}